# -*- coding: utf-8 -*-
# https://pythonhosted.org/gearman/client.html#extending-the-client

from gearman import GearmanClient
from gearman.constants import JOB_UNKNOWN
from function import get_config

def check_request_status(request):
    if request.complete:
        print "Job %s finished! Result: %s - %s" % (request.job.unique, request.state, request.result)
    elif request.timed_out:
        print "Job %s timed out!" % request.job.unique
    elif request.state == JOB_UNKNOWN:
        print "Job %s connection failed!" % request.job.unique

server = get_config('Gearman_Job_Server', 'host')
client = GearmanClient([server])

request = client.submit_job('reverse', 'Hello, world!')
check_request_status(request)